package jianzhi_offer;

import java.util.ArrayList;


public class _41_和为S的两个数字 {
    public ArrayList<Integer> FindNumbersWithSum(int [] array, int sum) {
        ArrayList<Integer> res = new ArrayList<>();
        int i=0,j=array.length-1;
        while(i<j){
            int now = array[i]+array[j];
            if(now == sum){
                res = new ArrayList<>();
                res.add(array[i]);
                res.add(array[j]);
                return res;
            }else if(now < sum){
                ++i;
            }else{
                --j;
            }
        }
        return res;
    }
}
